import redis
import time

if __name__ == '__main__':
    cli = redis.StrictRedis(
        host="192.168.189.137",
        port=6379,
        db=2
    )
# 2 号 数据库准备就绪
    cli.flushdb()
# 右进右出
    cli.lpush("list1", 1, 2, 3, 4)
    print(cli.lrange("list1", 0, -1))
# 右进左出
    cli.rpush("list2", 1, 2, 3, 4)
    print(cli.lrange("list2", 0, -1))
# 切片查询
    print(cli.lrange("list2", 0, 2))
# insert 插入模式
    cli.linsert("list2", "before", 3, 3)
    cli.linsert("list2", "after", 2, 2)
    print(cli.lrange("list2", 0, -1))
# count 删除模式    不需要写 count 关键字
    cli.lrem("list2", 1, 2)
    print(cli.lrange("list2", 0, -1))
# trim 截取模式
    cli.ltrim("list1", 0, 2)
    print(cli.lrange("list1", 0, -1))
# rpop 边取边删模式
    print(cli.rpop("list1"))
    print(cli.lrange("list1", 0, -1))
